import { UserInfo } from '@/entity/user.entity'

export const useMenuStore = defineStore('menu', {
  state: () => ({
    navs: [] as Array<any>,
    token: null as any,
    userInfo: null as UserInfo,
    appFlushed: false,
    originMenus: [] as Array<any>,
    loadedMenus: [] as Array<any>,
    menusForRoute: [] as Array<any>,
    menusForNav: [] as Array<any>,
    dicts: [] as Array<Dict>
  }),
  getters: {
    fullToken(state) {
      return 'Bearer ' + state.token
    }
  },
  actions: {
    translateSimple(key: string): string {
      if (!key) return ''
      const t = this.dicts.find((x) => x.value === key)
      if (t) {
        return t.label
      } else {
        return key
      }
    }
  },
  persist: {
    storage: sessionStorage,
    paths: ['token']
  }
})
export class Dict {
  value: string = ''

  label: string = ''

  color: string = ''

  type: string = ''
}
